package de.mmis.core.sexpression.util.gui;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.SwingConstants;

import org.apache.log4j.Logger;

import de.mmis.core.base.Position;
import de.mmis.core.base.abstracttree.Tree;
import de.mmis.core.base.device.Device;
import de.mmis.core.base.event.Observable;
import de.mmis.core.base.gui.AbstractRepresentationComponent;
import de.mmis.core.base.gui.DeviceRepresentationComponent;
import de.mmis.core.base.gui.GUIComponent;

/**
 * default {@link DeviceRepresentationComponent} used for all types of
 * {@link Device}.
 * 
 * @author Christian Koch
 * 
 */
public class DefaultRepresentationComponent extends
		AbstractRepresentationComponent<Object> {

	private final static Logger LOGGER = Logger
			.getLogger(DefaultRepresentationComponent.class);

	private static final long serialVersionUID = -6966046212057592675L;

	public DefaultRepresentationComponent() {
		super(0, Object.class, "Default");
	}

	@Override
	public void initialize(Class<?> clazz) {
		this.setLayout(new GridLayout(1, 1));

		JLabel filler = new JLabel("?");
		filler.setHorizontalAlignment(SwingConstants.CENTER);
		this.add(filler);
	}

	@Override
	public void notify(Observable<? extends GUIEvent> sender, GUIEvent event) {
		LOGGER.info("default representation component of device "
				+ this.getDevice().getID()
				+ " got message"
				+ (sender == null ? "" : " from "
						+ ((GUIComponent<?>) sender).toString()) + ": "
				+ Tree.fromObject(event, true));
	}

	@Override
	public Position getRepresentationDimension() {
		return new Position(1, 1);
	}
}
